<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>
<title>Coverage for c:\program files\python26\lib\multiprocessing\util</title>
<link rel='stylesheet' href='style.css' type='text/css'>
<script type='text/javascript' src='jquery-1.3.2.min.js'></script>
<script type='text/javascript'>
function toggle_lines(btn, cls) {
    var btn = $(btn);
    var hide = "hide_"+cls;
    if (btn.hasClass(hide)) {
        $("#source ."+cls).removeClass(hide);
        btn.removeClass(hide);
    }
    else {
        $("#source ."+cls).addClass(hide);
        btn.addClass(hide);
    }
}
</script>
</head>
<body>
<div id='header'>
    <div class='content'>
        <h1>Coverage for <b>c:\program files\python26\lib\multiprocessing\util</b> :
            <span class='pc_cov'>21%</span>
        </h1>
        <h2 class='stats'>
            162 statements
            <span class='run hide_run' onclick='toggle_lines(this, "run")'>44 run</span>
            <span class='exc' onclick='toggle_lines(this, "exc")'>0 excluded</span>
            <span class='mis' onclick='toggle_lines(this, "mis")'>118 missing</span>
            
                <span class='par run hide_run' onclick='toggle_lines(this, "par")'>0 partial</span>
            
        </h2>
    </div>
</div>

<div id='source'>
<table cellspacing='0' cellpadding='0'>
<tr>
<td class='linenos' valign='top'>
<p class='pln'>1</p>
<p class='pln'>2</p>
<p class='pln'>3</p>
<p class='pln'>4</p>
<p class='pln'>5</p>
<p class='pln'>6</p>
<p class='pln'>7</p>
<p class='pln'>8</p>
<p class='stm run hide_run'>9</p>
<p class='stm run hide_run'>10</p>
<p class='stm run hide_run'>11</p>
<p class='stm run hide_run'>12</p>
<p class='pln'>13</p>
<p class='pln'>14</p>
<p class='stm run hide_run'>15</p>
<p class='pln'>16</p>
<p class='stm run hide_run'>17</p>
<p class='pln'>18</p>
<p class='pln'>19</p>
<p class='pln'>20</p>
<p class='pln'>21</p>
<p class='pln'>22</p>
<p class='pln'>23</p>
<p class='pln'>24</p>
<p class='pln'>25</p>
<p class='pln'>26</p>
<p class='pln'>27</p>
<p class='stm run hide_run'>28</p>
<p class='stm run hide_run'>29</p>
<p class='stm run hide_run'>30</p>
<p class='stm run hide_run'>31</p>
<p class='stm run hide_run'>32</p>
<p class='pln'>33</p>
<p class='stm run hide_run'>34</p>
<p class='stm run hide_run'>35</p>
<p class='pln'>36</p>
<p class='stm run hide_run'>37</p>
<p class='stm run hide_run'>38</p>
<p class='pln'>39</p>
<p class='stm run hide_run'>40</p>
<p class='stm mis'>41</p>
<p class='stm mis'>42</p>
<p class='pln'>43</p>
<p class='stm run hide_run'>44</p>
<p class='stm mis'>45</p>
<p class='stm mis'>46</p>
<p class='pln'>47</p>
<p class='stm run hide_run'>48</p>
<p class='stm mis'>49</p>
<p class='stm mis'>50</p>
<p class='pln'>51</p>
<p class='stm run hide_run'>52</p>
<p class='stm mis'>53</p>
<p class='stm mis'>54</p>
<p class='pln'>55</p>
<p class='stm run hide_run'>56</p>
<p class='pln'>57</p>
<p class='pln'>58</p>
<p class='pln'>59</p>
<p class='pln'>60</p>
<p class='stm mis'>61</p>
<p class='pln'>62</p>
<p class='stm mis'>63</p>
<p class='stm mis'>64</p>
<p class='stm mis'>65</p>
<p class='pln'>66</p>
<p class='stm mis'>67</p>
<p class='stm mis'>68</p>
<p class='stm mis'>69</p>
<p class='stm mis'>70</p>
<p class='pln'>71</p>
<p class='pln'>72</p>
<p class='stm mis'>73</p>
<p class='stm mis'>74</p>
<p class='stm mis'>75</p>
<p class='pln'>76</p>
<p class='stm mis'>77</p>
<p class='stm mis'>78</p>
<p class='pln'>79</p>
<p class='pln'>80</p>
<p class='stm mis'>81</p>
<p class='pln'>82</p>
<p class='stm mis'>83</p>
<p class='pln'>84</p>
<p class='stm run hide_run'>85</p>
<p class='pln'>86</p>
<p class='pln'>87</p>
<p class='pln'>88</p>
<p class='pln'>89</p>
<p class='stm mis'>90</p>
<p class='pln'>91</p>
<p class='stm mis'>92</p>
<p class='stm mis'>93</p>
<p class='stm mis'>94</p>
<p class='stm mis'>95</p>
<p class='stm mis'>96</p>
<p class='pln'>97</p>
<p class='stm mis'>98</p>
<p class='stm mis'>99</p>
<p class='stm mis'>100</p>
<p class='stm mis'>101</p>
<p class='pln'>102</p>
<p class='pln'>103</p>
<p class='pln'>104</p>
<p class='pln'>105</p>
<p class='pln'>106</p>
<p class='stm run hide_run'>107</p>
<p class='pln'>108</p>
<p class='stm mis'>109</p>
<p class='stm mis'>110</p>
<p class='stm mis'>111</p>
<p class='stm mis'>112</p>
<p class='stm mis'>113</p>
<p class='stm mis'>114</p>
<p class='stm mis'>115</p>
<p class='pln'>116</p>
<p class='pln'>117</p>
<p class='pln'>118</p>
<p class='pln'>119</p>
<p class='pln'>120</p>
<p class='stm run hide_run'>121</p>
<p class='stm run hide_run'>122</p>
<p class='pln'>123</p>
<p class='stm run hide_run'>124</p>
<p class='stm mis'>125</p>
<p class='stm mis'>126</p>
<p class='stm mis'>127</p>
<p class='stm mis'>128</p>
<p class='stm mis'>129</p>
<p class='stm mis'>130</p>
<p class='stm mis'>131</p>
<p class='pln'>132</p>
<p class='stm run hide_run'>133</p>
<p class='stm mis'>134</p>
<p class='pln'>135</p>
<p class='pln'>136</p>
<p class='pln'>137</p>
<p class='pln'>138</p>
<p class='pln'>139</p>
<p class='stm run hide_run'>140</p>
<p class='stm run hide_run'>141</p>
<p class='pln'>142</p>
<p class='pln'>143</p>
<p class='stm run hide_run'>144</p>
<p class='pln'>145</p>
<p class='pln'>146</p>
<p class='pln'>147</p>
<p class='stm run hide_run'>148</p>
<p class='stm mis'>149</p>
<p class='pln'>150</p>
<p class='stm mis'>151</p>
<p class='stm mis'>152</p>
<p class='pln'>153</p>
<p class='stm mis'>154</p>
<p class='pln'>155</p>
<p class='stm mis'>156</p>
<p class='stm mis'>157</p>
<p class='stm mis'>158</p>
<p class='stm mis'>159</p>
<p class='pln'>160</p>
<p class='stm mis'>161</p>
<p class='pln'>162</p>
<p class='stm run hide_run'>163</p>
<p class='pln'>164</p>
<p class='pln'>165</p>
<p class='pln'>166</p>
<p class='stm mis'>167</p>
<p class='stm mis'>168</p>
<p class='stm mis'>169</p>
<p class='stm mis'>170</p>
<p class='pln'>171</p>
<p class='stm mis'>172</p>
<p class='pln'>173</p>
<p class='stm mis'>174</p>
<p class='stm mis'>175</p>
<p class='pln'>176</p>
<p class='stm mis'>177</p>
<p class='pln'>178</p>
<p class='stm run hide_run'>179</p>
<p class='pln'>180</p>
<p class='pln'>181</p>
<p class='pln'>182</p>
<p class='stm mis'>183</p>
<p class='stm mis'>184</p>
<p class='stm mis'>185</p>
<p class='stm mis'>186</p>
<p class='pln'>187</p>
<p class='stm mis'>188</p>
<p class='pln'>189</p>
<p class='pln'>190</p>
<p class='stm run hide_run'>191</p>
<p class='pln'>192</p>
<p class='pln'>193</p>
<p class='pln'>194</p>
<p class='stm mis'>195</p>
<p class='pln'>196</p>
<p class='stm run hide_run'>197</p>
<p class='stm mis'>198</p>
<p class='stm mis'>199</p>
<p class='stm mis'>200</p>
<p class='stm mis'>201</p>
<p class='pln'>202</p>
<p class='stm mis'>203</p>
<p class='stm mis'>204</p>
<p class='pln'>205</p>
<p class='stm mis'>206</p>
<p class='pln'>207</p>
<p class='stm mis'>208</p>
<p class='stm mis'>209</p>
<p class='stm mis'>210</p>
<p class='stm mis'>211</p>
<p class='stm mis'>212</p>
<p class='stm mis'>213</p>
<p class='stm mis'>214</p>
<p class='pln'>215</p>
<p class='pln'>216</p>
<p class='stm run hide_run'>217</p>
<p class='pln'>218</p>
<p class='pln'>219</p>
<p class='pln'>220</p>
<p class='pln'>221</p>
<p class='pln'>222</p>
<p class='pln'>223</p>
<p class='stm mis'>224</p>
<p class='stm mis'>225</p>
<p class='pln'>226</p>
<p class='stm mis'>227</p>
<p class='pln'>228</p>
<p class='stm mis'>229</p>
<p class='stm mis'>230</p>
<p class='pln'>231</p>
<p class='stm mis'>232</p>
<p class='stm mis'>233</p>
<p class='stm mis'>234</p>
<p class='stm mis'>235</p>
<p class='stm mis'>236</p>
<p class='stm mis'>237</p>
<p class='stm mis'>238</p>
<p class='pln'>239</p>
<p class='stm mis'>240</p>
<p class='stm mis'>241</p>
<p class='pln'>242</p>
<p class='pln'>243</p>
<p class='pln'>244</p>
<p class='pln'>245</p>
<p class='pln'>246</p>
<p class='stm run hide_run'>247</p>
<p class='pln'>248</p>
<p class='pln'>249</p>
<p class='pln'>250</p>
<p class='stm mis'>251</p>
<p class='pln'>252</p>
<p class='stm run hide_run'>253</p>
<p class='pln'>254</p>
<p class='stm run hide_run'>255</p>
<p class='pln'>256</p>
<p class='pln'>257</p>
<p class='stm mis'>258</p>
<p class='stm mis'>259</p>
<p class='stm mis'>260</p>
<p class='pln'>261</p>
<p class='stm mis'>262</p>
<p class='stm mis'>263</p>
<p class='stm mis'>264</p>
<p class='stm mis'>265</p>
<p class='pln'>266</p>
<p class='stm mis'>267</p>
<p class='stm mis'>268</p>
<p class='stm mis'>269</p>
<p class='pln'>270</p>
<p class='stm mis'>271</p>
<p class='stm mis'>272</p>
<p class='pln'>273</p>
<p class='stm run hide_run'>274</p>
<p class='pln'>275</p>
<p class='pln'>276</p>
<p class='pln'>277</p>
<p class='pln'>278</p>
<p class='pln'>279</p>
<p class='stm run hide_run'>280</p>
<p class='stm run hide_run'>281</p>
<p class='stm mis'>282</p>
<p class='stm mis'>283</p>
<p class='stm mis'>284</p>
<p class='stm mis'>285</p>
<p class='pln'>286</p>
<p class='stm run hide_run'>287</p>
<p class='stm run hide_run'>288</p>
<p class='stm mis'>289</p>
<p class='stm run hide_run'>290</p>
<p class='stm mis'>291</p>
    
</td>
<td class='text' valign='top'>
<p class='pln'><span class='com'>#</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># Module providing various facilities to other parts of the package</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'>#</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># multiprocessing/util.py</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'>#</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># Copyright (c) 2006-2008, R Oudkerk --- see COPYING.txt</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'>#</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='key'>import</span> <span class='nam'>itertools</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='key'>import</span> <span class='nam'>weakref</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='key'>import</span> <span class='nam'>atexit</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='key'>import</span> <span class='nam'>threading</span>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># we want threading to install it&#39;s</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># cleanup function before multiprocessing does</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='key'>from</span> <span class='nam'>multiprocessing</span><span class='op'>.</span><span class='nam'>process</span> <span class='key'>import</span> <span class='nam'>current_process</span><span class='op'>,</span> <span class='nam'>active_children</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='nam'>__all__</span> <span class='op'>=</span> <span class='op'>[</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='str'>&#39;sub_debug&#39;</span><span class='op'>,</span> <span class='str'>&#39;debug&#39;</span><span class='op'>,</span> <span class='str'>&#39;info&#39;</span><span class='op'>,</span> <span class='str'>&#39;sub_warning&#39;</span><span class='op'>,</span> <span class='str'>&#39;get_logger&#39;</span><span class='op'>,</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='str'>&#39;log_to_stderr&#39;</span><span class='op'>,</span> <span class='str'>&#39;get_temp_dir&#39;</span><span class='op'>,</span> <span class='str'>&#39;register_after_fork&#39;</span><span class='op'>,</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='str'>&#39;is_exiting&#39;</span><span class='op'>,</span> <span class='str'>&#39;Finalize&#39;</span><span class='op'>,</span> <span class='str'>&#39;ForkAwareThreadLock&#39;</span><span class='op'>,</span> <span class='str'>&#39;ForkAwareLocal&#39;</span><span class='op'>,</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='str'>&#39;SUBDEBUG&#39;</span><span class='op'>,</span> <span class='str'>&#39;SUBWARNING&#39;</span><span class='op'>,</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='op'>]</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'>#</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># Logging</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'>#</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='nam'>NOTSET</span> <span class='op'>=</span> <span class='num'>0</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='nam'>SUBDEBUG</span> <span class='op'>=</span> <span class='num'>5</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='nam'>DEBUG</span> <span class='op'>=</span> <span class='num'>10</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='nam'>INFO</span> <span class='op'>=</span> <span class='num'>20</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='nam'>SUBWARNING</span> <span class='op'>=</span> <span class='num'>25</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='nam'>LOGGER_NAME</span> <span class='op'>=</span> <span class='str'>&#39;multiprocessing&#39;</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='nam'>DEFAULT_LOGGING_FORMAT</span> <span class='op'>=</span> <span class='str'>&#39;[%(levelname)s/%(processName)s] %(message)s&#39;</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='nam'>_logger</span> <span class='op'>=</span> <span class='nam'>None</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='nam'>_log_to_stderr</span> <span class='op'>=</span> <span class='nam'>False</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='key'>def</span> <span class='nam'>sub_debug</span><span class='op'>(</span><span class='nam'>msg</span><span class='op'>,</span> <span class='op'>*</span><span class='nam'>args</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>_logger</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>_logger</span><span class='op'>.</span><span class='nam'>log</span><span class='op'>(</span><span class='nam'>SUBDEBUG</span><span class='op'>,</span> <span class='nam'>msg</span><span class='op'>,</span> <span class='op'>*</span><span class='nam'>args</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='key'>def</span> <span class='nam'>debug</span><span class='op'>(</span><span class='nam'>msg</span><span class='op'>,</span> <span class='op'>*</span><span class='nam'>args</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>_logger</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>_logger</span><span class='op'>.</span><span class='nam'>log</span><span class='op'>(</span><span class='nam'>DEBUG</span><span class='op'>,</span> <span class='nam'>msg</span><span class='op'>,</span> <span class='op'>*</span><span class='nam'>args</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='key'>def</span> <span class='nam'>info</span><span class='op'>(</span><span class='nam'>msg</span><span class='op'>,</span> <span class='op'>*</span><span class='nam'>args</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>_logger</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>_logger</span><span class='op'>.</span><span class='nam'>log</span><span class='op'>(</span><span class='nam'>INFO</span><span class='op'>,</span> <span class='nam'>msg</span><span class='op'>,</span> <span class='op'>*</span><span class='nam'>args</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='key'>def</span> <span class='nam'>sub_warning</span><span class='op'>(</span><span class='nam'>msg</span><span class='op'>,</span> <span class='op'>*</span><span class='nam'>args</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>_logger</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>_logger</span><span class='op'>.</span><span class='nam'>log</span><span class='op'>(</span><span class='nam'>SUBWARNING</span><span class='op'>,</span> <span class='nam'>msg</span><span class='op'>,</span> <span class='op'>*</span><span class='nam'>args</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='key'>def</span> <span class='nam'>get_logger</span><span class='op'>(</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='str'>&#39;&#39;&#39;</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; Returns logger used by multiprocessing</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; &#39;&#39;&#39;</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='key'>global</span> <span class='nam'>_logger</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>import</span> <span class='nam'>logging</span><span class='op'>,</span> <span class='nam'>atexit</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>logging</span><span class='op'>.</span><span class='nam'>_acquireLock</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>try</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='key'>not</span> <span class='nam'>_logger</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>_logger</span> <span class='op'>=</span> <span class='nam'>logging</span><span class='op'>.</span><span class='nam'>getLogger</span><span class='op'>(</span><span class='nam'>LOGGER_NAME</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>_logger</span><span class='op'>.</span><span class='nam'>propagate</span> <span class='op'>=</span> <span class='num'>0</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>logging</span><span class='op'>.</span><span class='nam'>addLevelName</span><span class='op'>(</span><span class='nam'>SUBDEBUG</span><span class='op'>,</span> <span class='str'>&#39;SUBDEBUG&#39;</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>logging</span><span class='op'>.</span><span class='nam'>addLevelName</span><span class='op'>(</span><span class='nam'>SUBWARNING</span><span class='op'>,</span> <span class='str'>&#39;SUBWARNING&#39;</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># XXX multiprocessing should cleanup before logging</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>hasattr</span><span class='op'>(</span><span class='nam'>atexit</span><span class='op'>,</span> <span class='str'>&#39;unregister&#39;</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>atexit</span><span class='op'>.</span><span class='nam'>unregister</span><span class='op'>(</span><span class='nam'>_exit_function</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>atexit</span><span class='op'>.</span><span class='nam'>register</span><span class='op'>(</span><span class='nam'>_exit_function</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>else</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>atexit</span><span class='op'>.</span><span class='nam'>_exithandlers</span><span class='op'>.</span><span class='nam'>remove</span><span class='op'>(</span><span class='op'>(</span><span class='nam'>_exit_function</span><span class='op'>,</span> <span class='op'>(</span><span class='op'>)</span><span class='op'>,</span> <span class='op'>{</span><span class='op'>}</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>atexit</span><span class='op'>.</span><span class='nam'>_exithandlers</span><span class='op'>.</span><span class='nam'>append</span><span class='op'>(</span><span class='op'>(</span><span class='nam'>_exit_function</span><span class='op'>,</span> <span class='op'>(</span><span class='op'>)</span><span class='op'>,</span> <span class='op'>{</span><span class='op'>}</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='key'>finally</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>logging</span><span class='op'>.</span><span class='nam'>_releaseLock</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>_logger</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='key'>def</span> <span class='nam'>log_to_stderr</span><span class='op'>(</span><span class='nam'>level</span><span class='op'>=</span><span class='nam'>None</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='str'>&#39;&#39;&#39;</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; Turn on logging and add a handler which prints to stderr</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; &#39;&#39;&#39;</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='key'>global</span> <span class='nam'>_log_to_stderr</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>import</span> <span class='nam'>logging</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>logger</span> <span class='op'>=</span> <span class='nam'>get_logger</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>formatter</span> <span class='op'>=</span> <span class='nam'>logging</span><span class='op'>.</span><span class='nam'>Formatter</span><span class='op'>(</span><span class='nam'>DEFAULT_LOGGING_FORMAT</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>handler</span> <span class='op'>=</span> <span class='nam'>logging</span><span class='op'>.</span><span class='nam'>StreamHandler</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>handler</span><span class='op'>.</span><span class='nam'>setFormatter</span><span class='op'>(</span><span class='nam'>formatter</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>logger</span><span class='op'>.</span><span class='nam'>addHandler</span><span class='op'>(</span><span class='nam'>handler</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>level</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>logger</span><span class='op'>.</span><span class='nam'>setLevel</span><span class='op'>(</span><span class='nam'>level</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>_log_to_stderr</span> <span class='op'>=</span> <span class='nam'>True</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>_logger</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'>#</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># Function returning a temp directory which will be removed on exit</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'>#</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='key'>def</span> <span class='nam'>get_temp_dir</span><span class='op'>(</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='com'># get name of a temp directory which will be automatically cleaned up</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>current_process</span><span class='op'>(</span><span class='op'>)</span><span class='op'>.</span><span class='nam'>_tempdir</span> <span class='key'>is</span> <span class='nam'>None</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>import</span> <span class='nam'>shutil</span><span class='op'>,</span> <span class='nam'>tempfile</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>tempdir</span> <span class='op'>=</span> <span class='nam'>tempfile</span><span class='op'>.</span><span class='nam'>mkdtemp</span><span class='op'>(</span><span class='nam'>prefix</span><span class='op'>=</span><span class='str'>&#39;pymp-&#39;</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>info</span><span class='op'>(</span><span class='str'>&#39;created temp directory %s&#39;</span><span class='op'>,</span> <span class='nam'>tempdir</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>Finalize</span><span class='op'>(</span><span class='nam'>None</span><span class='op'>,</span> <span class='nam'>shutil</span><span class='op'>.</span><span class='nam'>rmtree</span><span class='op'>,</span> <span class='nam'>args</span><span class='op'>=</span><span class='op'>[</span><span class='nam'>tempdir</span><span class='op'>]</span><span class='op'>,</span> <span class='nam'>exitpriority</span><span class='op'>=</span><span class='op'>-</span><span class='num'>100</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>current_process</span><span class='op'>(</span><span class='op'>)</span><span class='op'>.</span><span class='nam'>_tempdir</span> <span class='op'>=</span> <span class='nam'>tempdir</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>current_process</span><span class='op'>(</span><span class='op'>)</span><span class='op'>.</span><span class='nam'>_tempdir</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'>#</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># Support for reinitialization of objects when bootstrapping a child process</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'>#</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='nam'>_afterfork_registry</span> <span class='op'>=</span> <span class='nam'>weakref</span><span class='op'>.</span><span class='nam'>WeakValueDictionary</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='nam'>_afterfork_counter</span> <span class='op'>=</span> <span class='nam'>itertools</span><span class='op'>.</span><span class='nam'>count</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='key'>def</span> <span class='nam'>_run_after_forkers</span><span class='op'>(</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>items</span> <span class='op'>=</span> <span class='nam'>list</span><span class='op'>(</span><span class='nam'>_afterfork_registry</span><span class='op'>.</span><span class='nam'>items</span><span class='op'>(</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>items</span><span class='op'>.</span><span class='nam'>sort</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>for</span> <span class='op'>(</span><span class='nam'>index</span><span class='op'>,</span> <span class='nam'>ident</span><span class='op'>,</span> <span class='nam'>func</span><span class='op'>)</span><span class='op'>,</span> <span class='nam'>obj</span> <span class='key'>in</span> <span class='nam'>items</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>try</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>func</span><span class='op'>(</span><span class='nam'>obj</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>except</span> <span class='nam'>Exception</span><span class='op'>,</span> <span class='nam'>e</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>info</span><span class='op'>(</span><span class='str'>&#39;after forker raised exception %s&#39;</span><span class='op'>,</span> <span class='nam'>e</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='key'>def</span> <span class='nam'>register_after_fork</span><span class='op'>(</span><span class='nam'>obj</span><span class='op'>,</span> <span class='nam'>func</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>_afterfork_registry</span><span class='op'>[</span><span class='op'>(</span><span class='nam'>_afterfork_counter</span><span class='op'>.</span><span class='nam'>next</span><span class='op'>(</span><span class='op'>)</span><span class='op'>,</span> <span class='nam'>id</span><span class='op'>(</span><span class='nam'>obj</span><span class='op'>)</span><span class='op'>,</span> <span class='nam'>func</span><span class='op'>)</span><span class='op'>]</span> <span class='op'>=</span> <span class='nam'>obj</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'>#</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># Finalization using weakrefs</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'>#</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='nam'>_finalizer_registry</span> <span class='op'>=</span> <span class='op'>{</span><span class='op'>}</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='nam'>_finalizer_counter</span> <span class='op'>=</span> <span class='nam'>itertools</span><span class='op'>.</span><span class='nam'>count</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='key'>class</span> <span class='nam'>Finalize</span><span class='op'>(</span><span class='nam'>object</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='str'>&#39;&#39;&#39;</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; Class which supports object finalization using weakrefs</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; &#39;&#39;&#39;</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>__init__</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='nam'>obj</span><span class='op'>,</span> <span class='nam'>callback</span><span class='op'>,</span> <span class='nam'>args</span><span class='op'>=</span><span class='op'>(</span><span class='op'>)</span><span class='op'>,</span> <span class='nam'>kwargs</span><span class='op'>=</span><span class='nam'>None</span><span class='op'>,</span> <span class='nam'>exitpriority</span><span class='op'>=</span><span class='nam'>None</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>assert</span> <span class='nam'>exitpriority</span> <span class='key'>is</span> <span class='nam'>None</span> <span class='key'>or</span> <span class='nam'>type</span><span class='op'>(</span><span class='nam'>exitpriority</span><span class='op'>)</span> <span class='key'>is</span> <span class='nam'>int</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>obj</span> <span class='key'>is</span> <span class='key'>not</span> <span class='nam'>None</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_weakref</span> <span class='op'>=</span> <span class='nam'>weakref</span><span class='op'>.</span><span class='nam'>ref</span><span class='op'>(</span><span class='nam'>obj</span><span class='op'>,</span> <span class='nam'>self</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>else</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>assert</span> <span class='nam'>exitpriority</span> <span class='key'>is</span> <span class='key'>not</span> <span class='nam'>None</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_callback</span> <span class='op'>=</span> <span class='nam'>callback</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_args</span> <span class='op'>=</span> <span class='nam'>args</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_kwargs</span> <span class='op'>=</span> <span class='nam'>kwargs</span> <span class='key'>or</span> <span class='op'>{</span><span class='op'>}</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_key</span> <span class='op'>=</span> <span class='op'>(</span><span class='nam'>exitpriority</span><span class='op'>,</span> <span class='nam'>_finalizer_counter</span><span class='op'>.</span><span class='nam'>next</span><span class='op'>(</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>_finalizer_registry</span><span class='op'>[</span><span class='nam'>self</span><span class='op'>.</span><span class='nam'>_key</span><span class='op'>]</span> <span class='op'>=</span> <span class='nam'>self</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>__call__</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='nam'>wr</span><span class='op'>=</span><span class='nam'>None</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='str'>&#39;&#39;&#39;</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; &nbsp; &nbsp; Run the callback unless it has already been called or cancelled</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; &nbsp; &nbsp; &#39;&#39;&#39;</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>try</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>del</span> <span class='nam'>_finalizer_registry</span><span class='op'>[</span><span class='nam'>self</span><span class='op'>.</span><span class='nam'>_key</span><span class='op'>]</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>except</span> <span class='nam'>KeyError</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>sub_debug</span><span class='op'>(</span><span class='str'>&#39;finalizer no longer registered&#39;</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>else</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>sub_debug</span><span class='op'>(</span><span class='str'>&#39;finalizer calling %s with args %s and kwargs %s&#39;</span><span class='op'>,</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_callback</span><span class='op'>,</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_args</span><span class='op'>,</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_kwargs</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>res</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_callback</span><span class='op'>(</span><span class='op'>*</span><span class='nam'>self</span><span class='op'>.</span><span class='nam'>_args</span><span class='op'>,</span> <span class='op'>**</span><span class='nam'>self</span><span class='op'>.</span><span class='nam'>_kwargs</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_weakref</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_callback</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_args</span> <span class='op'>=</span> <span class='xx'>\</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_kwargs</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_key</span> <span class='op'>=</span> <span class='nam'>None</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>res</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>cancel</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='str'>&#39;&#39;&#39;</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; &nbsp; &nbsp; Cancel finalization of the object</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; &nbsp; &nbsp; &#39;&#39;&#39;</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>try</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>del</span> <span class='nam'>_finalizer_registry</span><span class='op'>[</span><span class='nam'>self</span><span class='op'>.</span><span class='nam'>_key</span><span class='op'>]</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>except</span> <span class='nam'>KeyError</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>pass</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>else</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_weakref</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_callback</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_args</span> <span class='op'>=</span> <span class='xx'>\</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_kwargs</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_key</span> <span class='op'>=</span> <span class='nam'>None</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>still_active</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='str'>&#39;&#39;&#39;</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; &nbsp; &nbsp; Return whether this finalizer is still waiting to invoke callback</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; &nbsp; &nbsp; &#39;&#39;&#39;</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_key</span> <span class='key'>in</span> <span class='nam'>_finalizer_registry</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>__repr__</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>try</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>obj</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_weakref</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>except</span> <span class='op'>(</span><span class='nam'>AttributeError</span><span class='op'>,</span> <span class='nam'>TypeError</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>obj</span> <span class='op'>=</span> <span class='nam'>None</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>obj</span> <span class='key'>is</span> <span class='nam'>None</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='str'>&#39;&lt;Finalize object, dead&gt;&#39;</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>x</span> <span class='op'>=</span> <span class='str'>&#39;&lt;Finalize object, callback=%s&#39;</span> <span class='op'>%</span> <span class='xx'>\</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>getattr</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>.</span><span class='nam'>_callback</span><span class='op'>,</span> <span class='str'>&#39;__name__&#39;</span><span class='op'>,</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_callback</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_args</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>x</span> <span class='op'>+=</span> <span class='str'>&#39;, args=&#39;</span> <span class='op'>+</span> <span class='nam'>str</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>.</span><span class='nam'>_args</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_kwargs</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>x</span> <span class='op'>+=</span> <span class='str'>&#39;, kwargs=&#39;</span> <span class='op'>+</span> <span class='nam'>str</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>.</span><span class='nam'>_kwargs</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_key</span><span class='op'>[</span><span class='num'>0</span><span class='op'>]</span> <span class='key'>is</span> <span class='key'>not</span> <span class='nam'>None</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>x</span> <span class='op'>+=</span> <span class='str'>&#39;, exitprority=&#39;</span> <span class='op'>+</span> <span class='nam'>str</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>.</span><span class='nam'>_key</span><span class='op'>[</span><span class='num'>0</span><span class='op'>]</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>x</span> <span class='op'>+</span> <span class='str'>&#39;&gt;&#39;</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='key'>def</span> <span class='nam'>_run_finalizers</span><span class='op'>(</span><span class='nam'>minpriority</span><span class='op'>=</span><span class='nam'>None</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='str'>&#39;&#39;&#39;</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; Run all finalizers whose exit priority is not None and at least minpriority</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; Finalizers with highest priority are called first; finalizers with</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; the same priority will be called in reverse order of creation.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; &#39;&#39;&#39;</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>minpriority</span> <span class='key'>is</span> <span class='nam'>None</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>f</span> <span class='op'>=</span> <span class='key'>lambda</span> <span class='nam'>p</span> <span class='op'>:</span> <span class='nam'>p</span><span class='op'>[</span><span class='num'>0</span><span class='op'>]</span><span class='op'>[</span><span class='num'>0</span><span class='op'>]</span> <span class='key'>is</span> <span class='key'>not</span> <span class='nam'>None</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='key'>else</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>f</span> <span class='op'>=</span> <span class='key'>lambda</span> <span class='nam'>p</span> <span class='op'>:</span> <span class='nam'>p</span><span class='op'>[</span><span class='num'>0</span><span class='op'>]</span><span class='op'>[</span><span class='num'>0</span><span class='op'>]</span> <span class='key'>is</span> <span class='key'>not</span> <span class='nam'>None</span> <span class='key'>and</span> <span class='nam'>p</span><span class='op'>[</span><span class='num'>0</span><span class='op'>]</span><span class='op'>[</span><span class='num'>0</span><span class='op'>]</span> <span class='op'>&gt;=</span> <span class='nam'>minpriority</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>items</span> <span class='op'>=</span> <span class='op'>[</span><span class='nam'>x</span> <span class='key'>for</span> <span class='nam'>x</span> <span class='key'>in</span> <span class='nam'>_finalizer_registry</span><span class='op'>.</span><span class='nam'>items</span><span class='op'>(</span><span class='op'>)</span> <span class='key'>if</span> <span class='nam'>f</span><span class='op'>(</span><span class='nam'>x</span><span class='op'>)</span><span class='op'>]</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>items</span><span class='op'>.</span><span class='nam'>sort</span><span class='op'>(</span><span class='nam'>reverse</span><span class='op'>=</span><span class='nam'>True</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>for</span> <span class='nam'>key</span><span class='op'>,</span> <span class='nam'>finalizer</span> <span class='key'>in</span> <span class='nam'>items</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>sub_debug</span><span class='op'>(</span><span class='str'>&#39;calling %s&#39;</span><span class='op'>,</span> <span class='nam'>finalizer</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>try</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>finalizer</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>except</span> <span class='nam'>Exception</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>import</span> <span class='nam'>traceback</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>traceback</span><span class='op'>.</span><span class='nam'>print_exc</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>minpriority</span> <span class='key'>is</span> <span class='nam'>None</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>_finalizer_registry</span><span class='op'>.</span><span class='nam'>clear</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'>#</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># Clean up on exit</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'>#</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='key'>def</span> <span class='nam'>is_exiting</span><span class='op'>(</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='str'>&#39;&#39;&#39;</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; Returns true if the process is shutting down</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; &#39;&#39;&#39;</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>_exiting</span> <span class='key'>or</span> <span class='nam'>_exiting</span> <span class='key'>is</span> <span class='nam'>None</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='nam'>_exiting</span> <span class='op'>=</span> <span class='nam'>False</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='key'>def</span> <span class='nam'>_exit_function</span><span class='op'>(</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='key'>global</span> <span class='nam'>_exiting</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>info</span><span class='op'>(</span><span class='str'>&#39;process shutting down&#39;</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>debug</span><span class='op'>(</span><span class='str'>&#39;running all &quot;atexit&quot; finalizers with priority &gt;= 0&#39;</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>_run_finalizers</span><span class='op'>(</span><span class='num'>0</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>for</span> <span class='nam'>p</span> <span class='key'>in</span> <span class='nam'>active_children</span><span class='op'>(</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>p</span><span class='op'>.</span><span class='nam'>_daemonic</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>info</span><span class='op'>(</span><span class='str'>&#39;calling terminate() for daemon %s&#39;</span><span class='op'>,</span> <span class='nam'>p</span><span class='op'>.</span><span class='nam'>name</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>p</span><span class='op'>.</span><span class='nam'>_popen</span><span class='op'>.</span><span class='nam'>terminate</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>for</span> <span class='nam'>p</span> <span class='key'>in</span> <span class='nam'>active_children</span><span class='op'>(</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>info</span><span class='op'>(</span><span class='str'>&#39;calling join() for process %s&#39;</span><span class='op'>,</span> <span class='nam'>p</span><span class='op'>.</span><span class='nam'>name</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>p</span><span class='op'>.</span><span class='nam'>join</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>debug</span><span class='op'>(</span><span class='str'>&#39;running the remaining &quot;atexit&quot; finalizers&#39;</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>_run_finalizers</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='nam'>atexit</span><span class='op'>.</span><span class='nam'>register</span><span class='op'>(</span><span class='nam'>_exit_function</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'>#</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># Some fork aware types</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'>#</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='key'>class</span> <span class='nam'>ForkAwareThreadLock</span><span class='op'>(</span><span class='nam'>object</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>__init__</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_lock</span> <span class='op'>=</span> <span class='nam'>threading</span><span class='op'>.</span><span class='nam'>Lock</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>acquire</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_lock</span><span class='op'>.</span><span class='nam'>acquire</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>release</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_lock</span><span class='op'>.</span><span class='nam'>release</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>register_after_fork</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='nam'>ForkAwareThreadLock</span><span class='op'>.</span><span class='nam'>__init__</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='key'>class</span> <span class='nam'>ForkAwareLocal</span><span class='op'>(</span><span class='nam'>threading</span><span class='op'>.</span><span class='nam'>local</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>__init__</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>register_after_fork</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='key'>lambda</span> <span class='nam'>obj</span> <span class='op'>:</span> <span class='nam'>obj</span><span class='op'>.</span><span class='nam'>__dict__</span><span class='op'>.</span><span class='nam'>clear</span><span class='op'>(</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>__reduce__</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>type</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>,</span> <span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
    
</td>
</tr>
</table>
</div>

</body>
</html>
